Accelerate the animation when it has been running for a while. (#143647).
authorSøren Sandmann <sandmann@redhat.com>
Sat, 4 Sep 2004 00:44:04 +0000 (00:44 +0000)
committerSøren Sandmann Pedersen <ssp@src.gnome.org>
Sat, 4 Sep 2004 00:44:04 +0000 (00:44 +0000)
Sat Sep  4 02:38:57 2004  Søren Sandmann  <sandmann@redhat.com>

* gtk/gtktoolbar.c (position): Accelerate the animation when it
has been running for a while. (#143647).

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtktoolbar.c

index e9889d8a841bbb3a59097b96e0acf4a35fa42c46..93a8896317b8f6754d3837ed2c8622d4de3e4b37 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Sep  4 02:38:57 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtktoolbar.c (position): Accelerate the animation when it
+       has been running for a while. (#143647).
+
 2004-09-03  Tor Lillqvist  <tml@iki.fi>
 
        * gtk-zip.sh.in: List the three theme gtkrc files separately, zip
index e9889d8a841bbb3a59097b96e0acf4a35fa42c46..93a8896317b8f6754d3837ed2c8622d4de3e4b37 100644 (file)
@@ -1,3 +1,8 @@
+Sat Sep  4 02:38:57 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtktoolbar.c (position): Accelerate the animation when it
+       has been running for a while. (#143647).
+
 2004-09-03  Tor Lillqvist  <tml@iki.fi>
 
        * gtk-zip.sh.in: List the three theme gtkrc files separately, zip
index e9889d8a841bbb3a59097b96e0acf4a35fa42c46..93a8896317b8f6754d3837ed2c8622d4de3e4b37 100644 (file)
@@ -1,3 +1,8 @@
+Sat Sep  4 02:38:57 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtktoolbar.c (position): Accelerate the animation when it
+       has been running for a while. (#143647).
+
 2004-09-03  Tor Lillqvist  <tml@iki.fi>
 
        * gtk-zip.sh.in: List the three theme gtkrc files separately, zip
index e9889d8a841bbb3a59097b96e0acf4a35fa42c46..93a8896317b8f6754d3837ed2c8622d4de3e4b37 100644 (file)
@@ -1,3 +1,8 @@
+Sat Sep  4 02:38:57 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtktoolbar.c (position): Accelerate the animation when it
+       has been running for a while. (#143647).
+
 2004-09-03  Tor Lillqvist  <tml@iki.fi>
 
        * gtk-zip.sh.in: List the three theme gtkrc files separately, zip
index b60a7f89ba99e3fc888ebddff09e84b199a400fd..9896604985db10f8610e51a0f003d8ff6a1eaf20 100644 (file)
@@ -53,6 +53,7 @@
 #include "gtkvbox.h"
 #include "gtkimage.h"
 #include "gtkseparatormenuitem.h"
+#include <math.h>
 
 typedef struct _ToolbarContent ToolbarContent;
 
@@ -71,7 +72,8 @@ typedef struct _ToolbarContent ToolbarContent;
                                    * in the homogeneous game. In units of
                                    * pango_font_get_estimated_char_width().
                                    */
-#define SLIDE_SPEED 600           /* How fast the items slide, in pixels per second */
+#define SLIDE_SPEED 600.0         /* How fast the items slide, in pixels per second */
+#define ACCEL_THRESHOLD 0.18      /* After how much time in seconds will items start speeding up */
 
 #define MIXED_API_WARNING                                              \
     "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
@@ -959,10 +961,27 @@ gtk_toolbar_size_request (GtkWidget      *widget,
 static gint
 position (gint from, gint to, gdouble elapsed)
 {
+  gint n_pixels;
+
+  if (elapsed <= ACCEL_THRESHOLD)
+    {
+      n_pixels = SLIDE_SPEED * elapsed;
+    }
+  else
+    {
+      /* The formula is a second degree polynomial in
+       * @elapsed that has the line SLIDE_SPEED * @elapsed
+       * as tangent for @elapsed == ACCEL_THRESHOLD.
+       * This makes @n_pixels a smooth function of elapsed time.
+       */
+      n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
+       SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
+    }
+  
   if (to > from)
-    return MIN (from + SLIDE_SPEED * elapsed, to);
+    return MIN (from + n_pixels, to);
   else
-    return MAX (from - SLIDE_SPEED * elapsed, to);
+    return MAX (from - n_pixels, to);
 }
 
 static void
@@ -1459,7 +1478,7 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
   else
     size = available_size;
   
-  /* calculate widths of items */
+  /* calculate widths and states of items */
   overflowing = FALSE;
   for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
     {